package model.expression.command;

import state.TabState;
import state.TurtleState;

public class Home extends AbstractCommandExpression {
	
	public Home(TabState ts) {
		super(ts);
	}
	
	@Override
	protected int getExpNumChildren() {
		return 0;
	}

	@Override
	public int evaluate() {
		int firstActiveTurtleReturnState = 0;
		// for each active turtle, evaluate
		for (int i = 0; i < tabSt.getActiveTurtle().size(); i++) {
			int turtleID = tabSt.getActiveTurtle().get(i);
			//for the first active turtle, record the return state
			if (i == 0){
				tabSt.turtlesMap.get(turtleID).setToHome();
				firstActiveTurtleReturnState = tabSt.turtlesMap.get(turtleID).disMoved();
			}
			else{
				tabSt.turtlesMap.get(turtleID).setToHome();
			}
			tabSt.turtlesMap.get(turtleID).notifyObservers();
		}
		return firstActiveTurtleReturnState;
	}

}
